<?php

namespace App\Http\Middleware;

use Closure;
use http\Message;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class AuthToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if($request->header('Authorization')){
            if(env('JWT_STATE') && !Auth::check()){
                return Fail(trans('login.token_off'),null,911);
            }
        }
        else{
            return Fail(trans('login.token_null'),["Message"=>__('login.token_null_tx')],910);
        }

        return $next($request);
    }
}
